﻿<%@ Control Language="VB" AutoEventWireup="false" CodeFile="BulkCreate.ascx.vb" Inherits="Control_Product_BulkCreate" %>
<%@ Register TagPrefix="aspNewControls" Namespace="NewControls" %>
<%@ Register TagPrefix="CE" Namespace="CuteEditor" Assembly="CuteEditor" %>
<script type="text/javascript">
    function ajaxJquery() {
        $(function () {

            $("#btnGenerateCode").click(function () {
                var text = $("#<%=txtMa.ClientID()%>").val();
                var stt = parseInt($("#<%=txtSTT.ClientID()%>").val());

                $(".MaSanPHam").each(function () {
                    $(this).val(text + padToFour(stt));
                    stt = stt + 1;
                });

            });
            //Upload Album 
            var str = "";
            $('#fileAlbum').uploadify({
                'uploader': '<%=ResolveUrl("~/uploadify/uploadify.swf")%>',
                'script': '<%=ResolveUrl("~/uploadify/UploadAlbum.ashx?folder=ImageStorage")%>',
                'cancelImg': '<%=ResolveUrl("~/uploadify/cancel.png")%>',
                'folder': '<%=ResolveUrl("~/Uploads")%>',
                'auto': false,
                'multi': true,
                'fileExt': '*.jpg;*.gif;*.png;*.jpeg;*.bmp',
                'fileDesc': 'Web Image Files (.JPG, .GIF, .PNG , .JPEG , .BMP)',
                'fileDataName': 'fileAlbum',
                'sizeLimit': 10240000,
                'onComplete': function (event, ID, fileObj, response, data) {
                    str += '<%= ConfigurationManager.AppSettings("ImageDomain") %>' + response.toString();
                },
                'onAllComplete': function (event, data) {
                    str += "0";
                    var myAlbum = new Array();
                    myAlbum = str.split(",");
                    str = "";
                    for (var i = 0; i < myAlbum.length - 1; i++) {
                        var index = 0;
                        index = Math.floor(Math.random() * 1000);
                        $(".GridBorder").append("<tr id='" + index + "' ><td Width='10%' class='text_list_links' align='center' >\
                                                     <a  class='delbutton' style='cursor:pointer;' onclick='cloneRow(" + index + ");' > thêm </a> | \
                                                     <a  class='delbutton' style='cursor:pointer;' onclick='RemoveRow(" + index + ");' > Xóa </a>\
                                                      </td>\
                                                  <td Width='15%' class='text_list_links' align='left' >\
                                                     <img alt=''   src='" + myAlbum[i] + "' Style='width: 100px; height: 68px; top: 0px; left: 0px;' class='ag-Jd-Pd' />\
                                                  </td>\
                                                  <td Width='10%' class='text_list_links' align='left' ><input type='text' class='MaSanPHam' id='IdMaSanPHam' style='width:85px !important' /></td>\
                                                  <td Width='10%' class='text_list_links' align='left' ><input type='text' class='GiaBan' id='IdGiaBan'  style='width:85px !important' /></td>\
                                                  <td Width='15%' class='text_list_links' align='left' ><select class='ProductCate' id='IdProductCate'></select></td>\
                                                  <td Width='15%' class='text_list_links' align='left' ><textarea class='MoTa' id='IdMoTa' cols='20' rows='4'></textarea></td>\
                                                  </tr>");
                    }
                    cloneSelect();
                }
            });

        });
    }


    function padToFour(number) {
        if (number <= 9999) { number = ("000" + number).slice(-4); }
        return number;
    }

    function RemoveRow(i) {
        $(".GridBorder #" + i).remove();

    }
    function showImage(i, title, desc) {
        $(".GridBorder").append("<tr id='" + i + "' ><td Width='10%' class='text_list_links' align='center' > <a  class='delbutton' style='cursor:pointer;' onclick='RemoveRow(" + i + ");' > Xóa </a> </td> <td Width='20%' class='text_list_links' align='left' > <img alt=''   src='" + title + "' Style='width: 100px; height: 68px; top: 0px; left: 0px;' class='ag-Jd-Pd' /> </td><td Width='20%' class='text_list_links' align='left' ><textarea id='TextArea1' cols='15' rows='4'>" + desc + "</textarea></td></tr>");
    }

    function getAllImages() {
        var strImage = "";
        var strComment = "";
        var strMaSanPham = "";
        var strGiaSanPham = "";
        var strProductCate = "";

        $(".GridBorder tr td img").each(function (e) {
            strImage += $(this).attr("src") + ","
        });
        $(".GridBorder tr td textarea").each(function (e) {
            strComment += $(this).val() + ";"
        });
        //ma code
        $(".GridBorder tr td .MaSanPHam").each(function (e) {
            strMaSanPham += $(this).val() + ";"
        });

        //Gia
        $(".GridBorder tr td .GiaBan").each(function (e) {
            strGiaSanPham += $(this).val() + ";"
        });

        //LoaiSanPham
        $(".GridBorder tr td .ProductCate").each(function (e) {
            strProductCate += $(this).val() + ";"
        });

        $("#<%=hidStrImage.ClientID()%>").val(strImage + '0');
        $("#<%=hidStrCommnet.ClientID()%>").val(strComment + '0');
        $("#<%=hidstrMaSanPham.ClientID()%>").val(strMaSanPham + '0');
        $("#<%=hidstrGiaSanPham.ClientID()%>").val(strGiaSanPham + '0');
        $("#<%=hidstrProductCate.ClientID()%>").val(strProductCate + '0');
    }

    function cloneSelect() {
        $(".GridBorder .ProductCate").each(function () {
            $('#<%=ddlType.ClientID()%>').find('option').clone().appendTo($(this));
        });
    }

    function cloneRow(id) {
        //$("#" + id).clone().appendTo($(".GridBorder"));
        var abc = $("#" + id).html();
        var index = 0;
        index = Math.floor(Math.random() * 1000);
        var cdf = "<tr id='" + index + "' >" + abc.replace(id, index).replace(id, index) + "</tr>"
        $(".GridBorder").append(cdf);
    }


</script>
<asp:UpdatePanel ID="uplProduct" runat="server">
    <ContentTemplate>
        <div class="content_porletform">
            <div class="HeadTitle">
                <h3>
                    <asp:Label ID="Label2" runat="server" Text="THÊM NHIỀU SẢN PHẨM" /></h3>
            </div>
            <div class="box_contentform">
                <div class="box_scroll_grid">
                    <div class="DivRow">
                        <div class="DivLabel">
                            <asp:Label ID="Label3" CssClass="TextLabel" runat="server" Text="Thêm Sản phẩm" />
                            <span class="fieldRequired">
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ControlToValidate="hidStrImage"
                                    Display="None" ErrorMessage="Vui lòng chọn ảnh Album."></asp:RequiredFieldValidator>
                            </span>
                        </div>
                        <div class="DivTextBox">
                            <input id="fileAlbum" name="file_upload" type="file" />
                            <a href="javascript:$('#fileAlbum').uploadifyUpload();">Upload Files</a>
                        </div>
                    </div>
                    <div>
                        <div class="DivLabel">
                            Mã:
                        </div>
                        <div class="DivTextBox">
                            Chữ số
                            <asp:TextBox ID="txtMa" CssClass="TextBox" runat="server"></asp:TextBox>
                            bắt đầu:
                            <asp:TextBox ID="txtSTT" CssClass="TextBox" runat="server"></asp:TextBox>
                            <input type="button" id="btnGenerateCode" class="btn" value="Sinh mã" />
                        </div>
                    </div>
                    <div class="DivRow">
                        <div class="DivLabel">
                            &nbsp;</div>
                        <div style="width: 100%;" class="DivTextBox">
                            <table cellpadding="0" width="99%" cellspacing="0" border="1" class="GridBorder">
                                <tr>
                                    <td width='10%' class='text_list_links' align='center'>
                                    </td>
                                    <td width='20%' class='text_list_links' align='left'>
                                        Ảnh
                                    </td>
                                    <td width='20%' class='text_list_links' align='left'>
                                        Mã sản phẩm
                                    </td>
                                    <td width='20%' class='text_list_links' align='left'>
                                        Giá bán
                                    </td>
                                    <td width='20%' class='text_list_links' align='left'>
                                        Loại sản phẩm
                                    </td>
                                    <td width='20%' class='text_list_links' align='left'>
                                        Mô tả
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </div>
                    <div class="DivRow" style="display: none">
                        <asp:DropDownList ID="ddlType" runat="server">
                        </asp:DropDownList>
                    </div>
                    <div class="DivRow">
                        <div class="DivLabel">
                            &nbsp;&nbsp;&nbsp;</div>
                        <div class="DivTextBox">
                            <asp:Button ID="btnSave" runat="server" OnClientClick="getAllImages();" Text=" Lưu "
                                CssClass="btn" />
                            <asp:Button ID="btnHuy" CausesValidation="false" runat="server" Text=" Hủy " CssClass="btn" />&nbsp;
                        </div>
                    </div>
                </div>
                <div style="display: none">
                    <asp:HiddenField ID="hidID" Value="0" runat="server" />
                    <asp:TextBox ID="hidImagePath" Text="" runat="server" />
                    <asp:TextBox ID="hidStrImage" Text="" runat="server" />
                    <asp:TextBox ID="hidStrCommnet" Text="" runat="server" />
                    <asp:TextBox ID="hidStrMaSanPham" Text="" runat="server" />
                    <asp:TextBox ID="hidstrGiaSanPham" Text="" runat="server" />
                    <asp:TextBox ID="hidStrProductCate" Text="" runat="server" />
                </div>
            </div>
        </div>
    </ContentTemplate>
</asp:UpdatePanel>
